package com.telit.firecommand.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.common.exception.ForestBaseException;
import com.telit.firecommand.dao.CommSpreadAnalysisDao;
import com.telit.firecommand.entity.CommSpreadAnalysis;
import com.telit.firecommand.service.SpreadAnalysisService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author:zhangwei
 * @Description:
 * @Time:Created on 2021/9/14 17:40
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SpreadAnalysisServiceImpl extends ServiceImpl<CommSpreadAnalysisDao, CommSpreadAnalysis> implements SpreadAnalysisService {
    /**
     * 新增蔓延分析表信息
     * @param spreadAnalysis
     */
    @Override
    public Long add(CommSpreadAnalysis spreadAnalysis) {
        if(baseMapper.insert(spreadAnalysis)<=0){
            throw new ForestBaseException("新增蔓延分析表信息失败");
        }
        return spreadAnalysis.getId();
    }

    /**
     * 分页条件蔓延分析表信息
     * @param current
     * @param size
     * @param spreadAnalysis
     * @return
     */
    @Override
    public IPage<CommSpreadAnalysis> selectByPage(Integer current, Integer size, CommSpreadAnalysis spreadAnalysis) {
        IPage<CommSpreadAnalysis> spreadAnalysisIPage=new Page<>(current,size);
        return baseMapper.selectPageByCondition(spreadAnalysisIPage,spreadAnalysis);
    }

    /**
     * 无分页条件查询蔓延分析表信息
     * @param spreadAnalysis
     * @return
     */
    @Override
    public List<CommSpreadAnalysis> selectByNoPage(CommSpreadAnalysis spreadAnalysis) {

        return baseMapper.selectByConditionNoPage(spreadAnalysis);
    }

    /**
     * 修改蔓延分析表信息
     * @param spreadAnalysis
     */
    @Override
    public void updateData(CommSpreadAnalysis spreadAnalysis) {
        if(baseMapper.updateById(spreadAnalysis)<=0){
            throw new ForestBaseException("修改蔓延分析表信息失败");
        }
    }

    /**
     * 根据ID删除蔓延分析表信息
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        if(baseMapper.deleteById(id)<=0){
            throw new ForestBaseException("根据ID删除蔓延分析表信息失败");
        }
    }

    /**
     * 根据火情ID查询蔓延分析信息
     * @param fireId
     */
    @Override
    public CommSpreadAnalysis getInfoByFireId(Long fireId) {
        return baseMapper.selectInfoByFireId(fireId);
    }
}
